/**
*
* Copyright (c) 2011 galaxy-union team.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
*  Abstract:
*
*
*  Author:
*    freecnjet (freecnjet@gmail.com)
*
*  Revision History:
*    Created on: 2011-02-24
*
*/


#ifndef STD_C_H
#define STD_C_H


//
// assert.h
//
#ifdef  RELEASE
  #define glxAssert(_Expression)     ((void)0)
#else
  #if PLATFORM==PLATFORM_WINDOWS
  EXTERN_C void glxErrorMsg( const wchar_t* msg, const wchar_t* file, unsigned line );
  #define glxAssert(_exp) (void)( (!!(_exp)) || (glxErrorMsg(L(#_exp), L(__FILE__), __LINE__),0) )
  #else
  EXTERN_C void glxErrorMsg( const char* msg, const char* file, unsigned line );
  #define glxAssert(_exp) (void)( (!!(_exp)) || (glxErrorMsg(#_exp, __FILE__, __LINE__),0) )
  #endif
#endif

//
// ctype.h
//
inline int glxIsalnum ( int c ) {
	return ('a'<=c&&c<='z' || 'A'<=c&&c<='Z' || '0'<=c&&c<='9') ? 1 : 0;
}

inline int glxIsalpha ( int c ) {
	return ('a'<=c&&c<='z' || 'A'<=c&&c<='Z') ? 1 : 0;
}

EXTERN_C int glxIscntrl( int c );

inline int glxIsdigit( int c ) {
	return ('0'<=c&&c<='9') ? 1 : 0;
}

//isgraph

inline int glxIslower( int c ) {
	return ('a'<=c&&c<='z') ? 1 : 0;
}

//int isprint ( int c );
//int ispunct ( int c );

inline int glxIsspace ( int c ) {
    return (' '==c || '\t'==c || '\n'==c || '\v'==c || '\f'==c || '\r'==c) ? 1 : 0;
}

inline int glxIsupper ( int c ) {
	return ('A'<=c&&c<='Z') ? 1 : 0;
}

inline int glxIsxdigit ( int c ) {
	return (('0'<=c&&c<='9') || ('A'<=c&&c<='F')|| ('a'<=c&&c<='f')) ? 1 : 0;
}

inline int glxTolower ( int c ) {
	return ('A'<=c&&c<='Z') ? (c+'a'-'A') : c;
}

inline int glxToupper ( int c ) {
	return ('a'<=c&&c<='z') ? (c-'a'+'A') : c;
}


//
// errno.h
//
EXTERN_C void glxSetError( long e );
EXTERN_C long glxGetError();


//
// float.h
// iso646.h
//

//
// limits.h
//
#define GLXY_CHAR_BIT  8
#define GLXY_SCHAR_MIN -127
#define GLXY_SCHAR_MAX 127
#define GLXY_UCHAR_MAX 255
#define GLXY_SHRT_MIN  -32767
#define GLXY_SHRT_MAX  32767
#define GLXY_USHRT_AMX 65535
#define GLXY_LONG_MIN  -2147483647
#define GLXY_LONG_MAX  2147483647
#define GLXY_ULONG_MAX 4294967295


//
// locale.h
//


//
// math.h
//
// Constants.
#undef  PI
#define PI 					(3.1415926535897932)
#define SMALL_NUMBER		(1.e-8)
#define KINDA_SMALL_NUMBER	(1.e-4)
#define BIG_NUMBER			(3.4e+38f)
#define INV_PI			    (0.31830988618)
#define HALF_PI			    (1.57079632679)

//acos, asin, atn, atan2, ceil, cos, exp, fabs, floor, fmod, log, log10, modf, pow, sin, sqrt, tan,
//exp2, max, min, hypot, log2, round, invsqrt
//TODO:


//
// setjmp.h
// signal.h
// stdarg.h
//


//
// stddef.h
//
#ifndef NULL
#define NULL    0
#endif

#ifndef size_t
typedef unsigned long size_t;
#endif


//
// stdio.h
//
EXTERN_C int glxPrintf (char *str, const char *format, ...);
EXTERN_C int glxSprintf (char *str, const char *format, ...);
EXTERN_C int glxSscanf (const char *str, const char *format, ...);


//
// stdlib.h
//
// atof, atoi, atol, strtod, strtol, strtoul, strtoll, strtoull
// rand, srand, malloc, calloc, realloc, free
// abort, atexit, exit, getenv, system, abs
// mbtowc, wctomb, mbstowcs, wcstombs
// TODO:


//
// string.h
//
// memcpy, memmove, memchr, memcmp, memset, strcat, strncat, strchr,
// strrchr, strcmp, strncmp, strcoll, strcpy, strncpy, strerror,
// strlen, strspn, strpbrk, strstr, strtok, strxfrm.
// TODO:


//
// time.h
//
// asctime, clock, ctime, difftime, gmtime, localtime, mktime, time,
// strftime, strptime, timegm,
// TODO:




